package thread;

// 方法二： 实现 Runnable, 重写 run
class MyRunnable implements Runnable {
    @Override
    public void run() {
        for (int i = 0; i < 5; i++) {
            System.out.println("hello thread !");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("线程结束 !");
    }
}
public class demo2 {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new MyRunnable());
        System.out.println("线程启动2 !");
        t.start();
        System.out.println("主线程结束 !");
    }

}
